﻿using System;
using ImmediatePropertyConstraints.Model;
using NUnit.Framework;
using Xtensive.Orm;
using Xtensive.Orm.Configuration;

namespace ImmediatePropertyConstraints
{
  public class Program
  {
    [Test]
    public static void Main()
    {
      // Loading domain configuration section with name "Default".
      var domainConfiguration = DomainConfiguration.Load("Default");
      var domain = Domain.Build(domainConfiguration);

      // Opening session
      using (var session = domain.OpenSession()) {
        using (var t = session.OpenTransaction()) {

          var entity = new MyEntity(session);
          try {
            // The exception is thrown on setting invalid value to the property
            entity.Text = string.Empty;
          }
          catch (Xtensive.Orm.Validation.ConstraintViolationException exception) {
            Console.WriteLine(exception);
          }
          t.Complete();
        }
      }
    }
  }
}
